﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Core.Interface;

namespace PServiceBus.Core.Runtime.ComponentServices {
    [Serializable]
    public class ComponentServiceInfo : IIdentifiable {
        public long TotalMessageProcessed { get; set; }
        public int ExpectedMessageAverage { get; set; }
        public string Address { get; set; }
        public string AddressID { get; set; }
        public string Name { get; set; }
        public static ComponentServiceInfo New {
            get {
                return new ComponentServiceInfo();
            }
        }

        private static Random _random = new Random();

        /// <summary>
        /// http://www.math.utah.edu/~pocock/lbnamed.html
        /// </summary>
        /// <returns></returns>
        public long GetRating() {
            var heuristic = 3;
            var fudge = (_random.Next(10) + 1) * (ExpectedMessageAverage / 5);
            return ExpectedMessageAverage + (heuristic * (TotalMessageProcessed * 100)) + fudge;
        }

        public ComponentServiceInfo() {
            ID = Guid.NewGuid();
        }
        #region IIdentifiable Members

        public Guid ID { get; set; }

        #endregion
    }
}
